package question.list;

import java.util.Arrays;

/**
 * @author: 26233
 * @create: 2022-09-18 19:47:28
 * @Description
 **/

public class MyList {

    MyNode root;

    public void add(Integer[] vs) {
        Arrays.stream(vs).forEach(this::add);
    }

    public void add(Integer v) {
        MyNode t = root;
        MyNode newNode = new MyNode(v);
        if (t == null) {
            root = newNode;
        }else {
            while (t.next != null) {
                t = t.next;
            }
            t.next = newNode;
        }
    }

    // 单链表逆转
    public MyNode reverseList(MyNode root) {
        if (root.next == null) {
            this.root = root;
            return root;
        }
        MyNode t = reverseList(root.getNext());
        root.setNext(null);
        t.setNext(root);
        return root;
    }

    public static void main(String[] args) {

        Integer[] vs = {1,2,3,4,5};
        MyList myList = new MyList();
        myList.add(vs);

        myList.reverseList(myList.root);

        System.out.println();

    }

}
